﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Collections;

namespace AUV5.Web.Pages
{
    public partial class Index : PageBaseFrontend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindService();

                bindShare();
            }
            if (base.IsVerified)
            {

            }
        }

        //绑定成果分享
        private void bindShare()
        {
            int recordcount = 0;
            repShare.DataSource = BLL.WorksShareBLL.Instance.GetPagedShare(4, 1, ref recordcount);
            repShare.DataBind();
            if (recordcount == 0)
            {
                divShare.Visible = false;
            }
            if (0 < recordcount && recordcount < 4)
            {
                MoreShare.Visible = true;
            }
        }

        //绑定某类别下的最热关键字
        public IList<string> GetHotKey()
        {
            if (Request["category"] != null)
            {

                return BLL.KeywordBLL.Instance.GetHotKeyByCategory(Request["category"].ToString()) ?? new List<string>();
            }
            else
            {
                return new List<string>();
            }
        }

        private void bindService()
        {
            //获取服务所需的参数
            //服务类别
            string category = "";
            string key = "";
            if (Request["category"] != null)
            {
                category = Request["category"].ToString();
            }
            if (Request["key"] != null)
            {
                key = Request["key"].ToString();
            }
            //排序规则
            string order = "Random";
            if (Request["orderby"] != null)
            {
                order = Request["orderby"].ToString();
            }
            //用户名
            string username = "";
            //分页
            int pageindex = AspNetPager1.CurrentPageIndex;
            int pagesize = AspNetPager1.PageSize;
            //总记录
            int recordcount = 0;
            int mode = 1;
            IList<AUV5.Model.ServiceInfo> list = BLL.ServiceInfoBLL.Instance.GetPagedServiceInfo(category, key, order, username, 0, mode, pageindex, pagesize, ref recordcount);

            UCServiceList1.Bind(list);
            AspNetPager1.RecordCount = recordcount;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bindService();
        }
    }
}